package createThread.cn.tedu.threaddemo.test6;

import java.util.Scanner;

public class Test2 {
    public static void main(String[] args) throws InterruptedException {
        String lock = "锁1";
        Thread t1 = new Thread(()->{
            synchronized (lock){
                System.out.println("t1 wait 之前");
                try {
                    lock.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("t1 wait 之后");
            }
        });
        Thread t2 = new Thread(()->{

            synchronized (lock){
                System.out.println("t2 notify 之前");
                System.out.println("请输入任意数字来触发notify");
                Scanner scanner = new Scanner(System.in);
                int i = scanner.nextInt();
                lock.notify();
                System.out.println("t2 notify 之后");
            }

        });
        t1.start();
        t2.start();
    }
}
